#include "StdAfx.h"
#include "skinlabel.h"

SkinLabel::SkinLabel(QWidget *parent)
	: QLabel(parent),hover(false)
{
	this->setMouseTracking(true);
	m_border = QColor(118,1,4);
}

SkinLabel::~SkinLabel()
{

}

bool SkinLabel::event(QEvent* e)
{
	switch(e->type())
	{
	case QEvent::Enter:
		emit Hover(m_MainBk);
		break;
	case QEvent::Leave:
		hover = false;
		emit Leave();
		this->update();
		break;
	default:
		break;
	}
	return __super::event(e);
}
void SkinLabel::paintEvent(QPaintEvent* e)
{
	QPainter paint(this);

	if( !m_bk.isNull() )
	{
		paint.drawPixmap(this->rect(), m_bk);
	}

	if(hover)
	{
		paint.setPen(m_border);
		paint.drawRect(0,0,this->rect().width()-1,this->rect().height()-1);
		paint.setPen(QColor(255,255,255));
		paint.drawRect(1,1,this->rect().width()-3,this->rect().height()-3);
	}

	return __super::paintEvent(e);
}
void SkinLabel::mouseMoveEvent(QMouseEvent* e)
{
	hover = true;
	this->update();
	return __super::mouseMoveEvent(e);
}
void SkinLabel::mousePressEvent(QMouseEvent* e)
{
	emit Click(m_MainBk);
	return __super::mousePressEvent(e);
}